home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / castools.zip / FAXGETE1.C < prev    next >
Text File  |  1990-01-05  |  3KB  |  98 lines

  1.  
  2.  
  3. /*
  4.    FAXGETE1.C  A high-level CAS Toolkit function.
  5.  
  6.    This function gets the Event Control information for an event.  This
  7.    is all the data about the event except the cover page and the files
  8.    transmitted.
  9.  
  10.    INPUT:  An event handle, possibly a queue number, and possibly a pointer to
  11.             a structure to return information in.
  12.  
  13.    OUTPUT: Returns a pointer to an Event Control File structure.
  14.            Also returns the queue that the event was found in.
  15. */
  16.  
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <malloc.h>
  21. #include <cas.h>
  22. #include <fax.h>
  23.  
  24. ECF * pascal FAXGetEventControlInfo(int EventHandle,
  25.                                     BYTE *queue,
  26.                                     ECF *EventInfo)
  27.  
  28. {
  29.   int FileHandle,                 /* returned from CASFind functions */
  30.       retval,                     /* for return value of CAS calls */
  31.       red;                        /* bytes read with the read() */
  32.   ECF *ECFp;                      /* Event Control File structure */
  33.   CECS CurrentEventInfo;
  34.  
  35.   FAXerrno = CASerrorcode = 0;      /* They keep it if nothing goes wrong */
  36.  
  37.   /* Choose whether to use the callers structure, or allocate our own. */
  38.   if (EventInfo) {
  39.     ECFp = EventInfo;
  40.   }
  41.   else {
  42.     ECFp = malloc(sizeof(ECF));
  43.     if (!ECFp) {
  44.       FAXerrno = OUTOFMEMORY;
  45.       return(NULL);
  46.     }
  47.   }
  48.  
  49.   /* If the event is currently executing, just get its control info */
  50.   if (EventHandle == CASGetCurrentEventStatus(&CurrentEventInfo)) {
  51.     memcpy(ECFp, &CurrentEventInfo.ControlFile, sizeof(ECF));
  52.     FAXerrno = EVENTISCURRENT;
  53.     *queue = UNKNOWN_QUEUE;
  54.     return(ECFp);
  55.   }
  56.  
  57.   /* If no queue specified, search all the queues for the given Event Handle */
  58.   if (*queue == UNKNOWN_QUEUE) {
  59.     for (*queue = TASK_QUEUE; *queue <= LOG_QUEUE; (*queue)++) {
  60.       retval = CASFindFirst(ANY_STATUS, SEARCH_FORWARD, *queue);
  61.       while (retval && (retval != EventHandle)) {
  62.         if (retval > 0) {           /* found an event, but not the one sought */
  63.           retval = CASFindNext(*queue);       /* so find next one */
  64.         }
  65.         else break;                           /* end of queue, or other error */
  66.       }
  67.       if (retval == EventHandle) break;        /* else go to next queue */
  68.     }                                          /* Done with all the queues */
  69.     if (retval != EventHandle) {       /* after all that, just give up! */
  70.       *queue = UNKNOWN_QUEUE;
  71.       FAXerrno = EVENTNOTFOUND;
  72.       CASerrorcode = -retval;
  73.       return(NULL);
  74.     }
  75.   }
  76.  
  77.   /* To get to here, the queue was given, or we found it anyway */
  78.   retval = CASOpenFile(EventHandle, 0, *queue);
  79.   if (retval < 0) {                            /* CAS error, get out */
  80.     FAXerrno = OPENFILE;
  81.     CASerrorcode = -retval;
  82.     return(NULL);
  83.   }
  84.   FileHandle = retval;
  85.  
  86.   red = read(FileHandle, ECFp, sizeof(ECF));        /* Finally, read it in! */
  87.   if (red != sizeof(ECF)) {
  88.     FAXerrno = CANTREADFILE;
  89.     return(NULL);
  90.   }
  91.   if (close(FileHandle) == -1) {
  92.     FAXerrno = CANTCLOSEFILE;          /* Warning only, we got what we wanted */
  93.   }
  94.   ECFp->RESERVED1 = 0;
  95.   memset(ECFp->RESERVED2, 0, RESERVED2LENGTH);
  96.   return(ECFp);
  97. }
  98.